package com.sicheng.lc.周赛.分类.模拟;

/**
 * @author zsc
 * @version 1.0
 * @date 2022/7/2 10:40
 */
public class 按符号重排数组 {
    //https://leetcode.cn/problems/rearrange-array-elements-by-sign/
    static int[] a = new int[(int) 1e5];
    static int[] b = new int[(int) 1e5];
    static int size;

    public int[] rearrangeArray(int[] nums) {
        size = nums.length >> 1;
        int index1 = 0, index0 = 0;
        for (int num : nums) {
            if (num > 0)
                a[index0++] = num;
            else
                b[index1++] = num;
        }

        for (int i = 0; i < nums.length; i += 2) {
            nums[i] = a[i >> 1];
            nums[i + 1] = a[i >> 1];
        }
        return nums;
    }
}
